home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvhist.cpp < prev    next >
C/C++ Source or Header  |  1998-01-05  |  3KB  |  125 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVHIST.CPP                           |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     History box implementation           |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #ifndef NOHIST
  16.  
  17. #define uses_string
  18. #define uses_cmd
  19. #define uses_hist
  20. #define uses_icons
  21.  
  22. #include "PVuses.h"
  23.  
  24. #define MAX_HISTORY_ENTRIES 32
  25.  
  26. struct Thistory_list
  27. {
  28.   void *id;
  29.   Tlb_list *list;
  30.   Thistory_list *next;
  31. };
  32.  
  33. static Thistory_list *first_history = NULL;
  34.  
  35. Tlb_list *registrate_history( void *id )
  36. {
  37.   Thistory_list *p;
  38.  
  39.   p = first_history;
  40.   while( p != NULL )
  41.   {
  42.     if( p->id == id ) return p->list;
  43.     p = p->next;
  44.   }
  45.   p = NEW( Thistory_list );
  46.   p->id = id;
  47.   p->list = NEW( Tlb_list );
  48.   p->next = first_history;
  49.   first_history = p;
  50.   return p->list;
  51. }
  52.  
  53. //Thistory publics:
  54.  
  55. Thistory::Thistory( void *_id ):
  56.   Tcombo()
  57. {
  58.   list = registrate_history( _id );
  59. }
  60.  
  61. Thistory::Thistory( Tlb_list *_list ):
  62.   Tcombo()
  63. {
  64.   list = _list;
  65. }
  66.  
  67. void Thistory::record_history( void )
  68. {
  69.   char s[256], t[256];
  70.   uint n;
  71.  
  72.   ( ( Tcombo_item * ) owner )->get_data( s );
  73.   if( !( *s ) ) return;
  74.   for( n = 0; n < list->vcount; n++ )
  75.   {
  76.     list->gettxt( n, t );
  77.     if( strcmp( t, s ) == 0 )
  78.     {
  79.       list->del( n );
  80.       break;
  81.     }
  82.   }
  83.   if( list->vcount == MAX_HISTORY_ENTRIES ) list->del( list->vcount );
  84.   list->ins( 0, s );
  85. }
  86.  
  87. //Thistory protected:
  88.  
  89. void Thistory::initialize( void )
  90. {
  91.   Tcombo::initialize();
  92.   ( (Tcombo_item *) owner )->options |= loASSOCIATED;
  93.   ( (Tcombo_item *) owner )->vcount = list->vcount;
  94.   ( (Tcombo_item *) owner )->hsize = list->hsize;
  95.   ( (Tcombo_item *) owner )->hmax_size = list->hmax_size;
  96.   ( (Tcombo_item *) owner )->overflow = list->overflow;
  97.   ( (Tcombo_item *) owner )->changed = list->changed;
  98. }
  99.  
  100. void Thistory::event_handler( Tevent &ev )
  101. {
  102.   if( ( ev.code != evCOMMAND ) || ( ev.CMD_CODE != cmDLG_RECORD_HISTORY ) )
  103.     Tcombo::event_handler( ev );
  104.   else
  105.     record_history();
  106. }
  107.  
  108. Tcombo_list * Thistory::init_combo_list( void )
  109. {
  110.   return NEW( Tcombo_list(
  111.     list->vcurrent,
  112.     open_xl - i_sb_up_len,
  113.     open_yl,
  114.     list )
  115.   );
  116. }
  117.  
  118. void Thistory::open_combo( void )
  119. {
  120.   Tcombo::open_combo();
  121.   list->top();
  122. }
  123.  
  124. #endif
  125.